package com.shxy.controller;

import com.shxy.common.ApiResult;
import com.shxy.controller.ui.ItemBean;
import com.shxy.entity.common.*;
import com.shxy.entity.common.enums.EthicEnum;
import com.shxy.entity.common.enums.GenderEnum;
import com.shxy.service.ICommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/v2/common")
public class CommonController {
    @Autowired
    ICommonService commonService;

    /**
     * 学位列表
     * @return
     */
    @GetMapping("/degree/list")
    public ApiResult getDegreeList(){
        return ApiResult.success(commonService.getDegreeList());
    }

    /**
     * 一级部门列表
     * @return
     */
    @GetMapping("/department/list")
    public ApiResult getDepartmentList(){
        List<ItemBean> list = commonService.getDepartmentList().stream().map(dept -> {
            return new ItemBean(dept.getCode(), dept.getName());
        }).collect(Collectors.toList());
        return ApiResult.success(list);
    }

    /**
     * 行政区划列表
     * @return
     */
    @GetMapping("/district/list")
    public ApiResult getDistrictList(){
        return ApiResult.success(commonService.getDistrictList());

    }

    /**
     * 学历列表
     * @return
     */
    @GetMapping("/education/list")
    public ApiResult getEducationList(){
        return ApiResult.success(commonService.getEducationList());
    }

    /**
     * 民族列表
     * @return
     */
    @GetMapping("/ethic/list")
    public ApiResult getEthicList(){
        return ApiResult.success(commonService.getEthicList());
    }

    /**
     * 性别列表
     * @return
     */
    @GetMapping("/gender/list")
    public ApiResult getGenderList(){
        return ApiResult.success(commonService.getGenderList());
    }

    /**
     * 获取级别列表
     * @return
     */
    @GetMapping("/level/list")
    public ApiResult getLevelList() {
        return ApiResult.success(commonService.getLevelList());
    }

    /**
     * 奖惩类型列表
     * @return
     */
    @GetMapping("/achieve/type/list")
    public ApiResult getAchieveTypeList() {
        return ApiResult.success(commonService.getAchieveTypeList());
    }

    /**
     * 身份列表
     * @return
     */
    @GetMapping("/identity/list")
    public ApiResult getIdentityList(){
        return ApiResult.success(commonService.getIdentityList());
    }

    /**
     * 政治面貌列表
     * @return
     */
    @GetMapping("/political/list")
    public ApiResult getPoliticalList(){
        return ApiResult.success(commonService.getPoliticalList());
    }

    /**
     * 职务列表
     * @return
     */
    @GetMapping("/position/list")
    public ApiResult getPositionList(){
        return ApiResult.success(commonService.getPositionList());
    }

    /**
     * 学科列表
     * @return
     */
    @GetMapping("/subject/list")
    public ApiResult getSubjectList(){
        return ApiResult.success(commonService.getSubjectList());
    }

    @PostMapping("/test/enum")
    public ApiResult testEnum(@RequestBody EthicEnum ethic) {
        return ApiResult.success(ethic.getCode());
    }
}
